﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace DFYE.Web.Controllers
{
    public class LookStudtenLoginFilter : AuthorizeAttribute
    {
        
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            string aa = filterContext.RouteData.Values["action"].ToString();
            //如果来至登录Action，直接返回
            if (aa == "Login") {
                return;
            }
            //未登录，跳转到登录Action

            if (filterContext.HttpContext.Session.IsNewSession == true
                || filterContext.HttpContext.Session["LookStudtenLoginUserID"] == null)
            {

                filterContext.Result = new RedirectResult("/students/Login");
            }
            else {
                int studentID=0;
                try
                {
                    studentID = (int)filterContext.HttpContext.Session["LookStudtenLoginUserID"];
                }
                catch
                {
                    filterContext.Result = new RedirectResult("/students/Login");
                }
                if (studentID == 0)
                {
                    filterContext.Result = new RedirectResult("/students/Login");
                }
            }

            
        }


    }
}